function Score(suffix, type_) {
	var type=type_
	var scale=(type=="horizontal")?300:100;
	var meter=document.getElementById("rating_"+suffix);
	var form=document.getElementById("form_"+suffix);
	var field=document.getElementById("form_"+suffix+"_field");
	var last_style=meter.style.backgroundPosition;
	var last_text=meter.innerHTML;
	meter.style.cursor="pointer";
	form.style.display="none";
	
	meter.onmouseout=function(e) {
		meter.innerHTML=last_text;
		meter.style.backgroundPosition=last_style;
	}
	meter.onmousemove=function(e) {
		if(type=="horizontal")
			procent=Math.round(100*(e.pageX-meter.offsetLeft)/scale);
		else
			procent=100-Math.round(100*(e.pageY-meter.offsetTop)/scale);
		if(procent<0)
			procent=0;
		if(procent>100)
			procent=100;
		meter.style.backgroundPosition=scale*(0.01*procent-1)+"px "+scale*(-0.01*procent+1)+"px";
		if(type=="horizontal")
			meter.innerHTML="oceniasz na "+procent+"%";
		else
			meter.innerHTML="<div class=\"big\">"+procent+"%</div> oceniasz na ";
		field.value=procent;
	}
	meter.onclick=function(e)	{
		form.submit();
	}
}

function ScoreHorizontal(suffix)	{
	Score(suffix, "horizontal");
}

function ScoreVertical(suffix)	{
	Score(suffix, "vertical");
}

function hide(id, label) {
	obj=document.getElementById(id);
	obj.style.display="none";
	link=document.createElement("a");
	link.appendChild(document.createTextNode(label));
	link.href="#"+id;
	link.hidden=obj;
	obj.parentNode.insertBefore(link, obj);
	link.onclick=function() {
		this.hidden.style.display="inherit";
		this.parentNode.removeChild(this);
	}
}

function rm(o) {
	while(o.tagName != "TR" && o.parentNode)
		o=o.parentNode;
	if(o.parentNode)
		o.parentNode.removeChild(o);
//	o=document.getElementById(id);
	return false;
}



function addActor() {
	tr=document.createElement("tr");
	
	selectAktor=tr.appendChild(document.createElement("td")).appendChild(document.createElement("select"));
	selectAktor.name="aktor";
	for(i in aktor) {
		option=selectAktor.appendChild(document.createElement("option"));
		option.appendChild(document.createTextNode(aktor[i]));
		option.value=i;
	}
	
	selectRola=tr.appendChild(document.createElement("td")).appendChild(document.createElement("select"));
	selectRola.name="rola";
	for(i in rola) {
		option=selectRola.appendChild(document.createElement("option"));
		option.appendChild(document.createTextNode(rola[i]));
		option.value=i;
	}
	
	usun=tr.appendChild(document.createElement("td")).appendChild(document.createElement("button"));
	usun.onclick=function(){rm(this)};
	usun.appendChild(document.createTextNode("usun"));

	document.getElementById("actors").appendChild(tr);						
}